//
//  MJStatues.swift
//  新浪微博
//
//  Created by MaJi on 16/4/11.
//  Copyright © 2016年 MaJi. All rights reserved.
//

import UIKit

class MJStatues: NSObject {

//    微博id
    var id:Int64 = 0
//    创建时间
    var created_at:String?
//    微博正文
    var text:String?
//    微博来源
    var source:String?
/// 转发,评论,赞的数量
    var reposts_count:Int = 0
    var comments_count:Int = 0
    var attitudes_count:Int = 0
//    1.用户属性
    var user:MJUser?
    init(dict:[String:AnyObject]) {
        super.init()
        self.setValuesForKeysWithDictionary(dict)
    }
//    2.转发微博 因为转发微博和原创微博的内容差不多,公用一个模型
    var retweeted_status:MJStatues?
//    3.图片(数组)
    var pic_urls:[MJStatusPicture]?
//    过滤空值
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key=="user" {
            user = MJUser(dict: value as! [String:AnyObject])
//            一定不要忘记return 否则就白写啦
            return
        }
        if key == "retweeted_status" {
            retweeted_status = MJStatues(dict: value as! [String:AnyObject])
            return
        }
        if key == "pic_urls" {
//            获取字典数组
            let dictArray = value as! [[String:String]]
            var tempArray = [MJStatusPicture]()
//            遍历字典数组,取出字典 转模型
            for item in dictArray {
                let picModel = MJStatusPicture(dict: item)
                tempArray.append(picModel)
            }
            pic_urls = tempArray
            return
        }
        super.setValue(value, forKey: key)
    }
}
